package com.example.datedemo.controller;

import com.example.datedemo.domain.MonthSample;
import com.example.datedemo.service.MonthSampleService;
import com.example.datedemo.service.dto.monthSample.MonthSampleAddDto;
import com.example.datedemo.service.dto.ResponseResult;
import com.example.datedemo.service.dto.monthSample.MonthSampleUpdateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Api("月相关")
@RestController
public class MonthSampleController {
    @Resource
    private MonthSampleService monthSampleService;

    @ApiOperation(value = "显示所有月")
    @GetMapping("/month/allMonth")
    public List<MonthSample> getAll() {
        return monthSampleService.selectAll();
    }

    @ApiOperation(value = "根据主键id显示Month")
    @GetMapping("/month/getMonthById/{id}")
    public ResponseResult getById(@PathVariable("id") String id) throws IOException {
        return monthSampleService.selectById(id);
    }

    @ApiOperation(value = "根据项目id和monthNumber显示Month")
    @GetMapping("/month/getMonthByMonthNumber/{projectId}/{monthNumber}")
    public ResponseResult getByMonth(@PathVariable("projectId")int projectId, @PathVariable("monthNumber") String monthNumber) throws IOException{
        return monthSampleService.selectByMonthNumber(projectId,monthNumber);
    }
    @ApiOperation(value = "新增一个Month")
    @PutMapping("/month/insertMonth")
    public ResponseResult insertMonthSample(@RequestBody MonthSampleAddDto monthSampleAddDto) {
        return monthSampleService.insertMonthSample(monthSampleAddDto);
    }

    @ApiOperation(value = "更新指定Month")
    @PutMapping("/month/updateMonth")
    public ResponseResult updateMonthSample(@RequestBody MonthSampleUpdateDto monthSampleUpdateDto) {
        return monthSampleService.updateMonthSample(monthSampleUpdateDto);
    }

    @ApiOperation(value = "根据主键id删除Month")
    @DeleteMapping("/month/deleteMonthById/{id}")
    public ResponseResult deleteMonthSampleById(@PathVariable String id) {
        return monthSampleService.deleteMonthSampleById(id);
    }
}
